home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgfx10.zip / EMS1.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-01  |  3KB  |  118 lines

  1. { Simple EMS demo that shows how to allocate 1 page of EMS memory
  2.   and push/pop a string to it.
  3.  
  4.   You can store most anything in EMS, as long as it doesn't exceed 16384
  5.   bytes PER page, you can use as many pages as you have available by the
  6.   EMS driver.
  7. }
  8.  
  9. uses dos,crt,ems;
  10.  
  11. { Declare our variables }
  12. var EMSVer : word;      { EMS Driver Version }
  13.     Handle : integer;   { Handle for the EMS page }
  14.     S      : string;    { String for putting in EMS }
  15.     StLen  : integer;   { String's length }
  16.  
  17.  
  18. { Main Procedure! }
  19. begin
  20.      clrscr;
  21.      writeln;
  22.  
  23.      { Initialize the EMS driver }
  24.      EMSVer := EMS_Init;
  25.  
  26.      { If EMSResult is greater than or equal to $80 then it is an EMS driver
  27.        error }
  28.      if (EMSResult >= $80) then
  29.      begin
  30.           { There was an EMS error, so display the description }
  31.           writeln('EMS Error:  ', EMS_ErrDesc[EMSResult]);
  32.           halt(1);
  33.      end
  34.      else if (EMSVer = 0) then
  35.      begin
  36.           writeln('EMS Demo:  No EMS driver found!');
  37.           halt(1);
  38.      end;
  39.  
  40.  
  41.      { Allocate 1 page of EMS memory }
  42.      handle := EMSAlloc(1);
  43.  
  44.      if (EMSResult>=$80) then
  45.      begin
  46.           { There was an EMS error, so display the description }
  47.           writeln('EMS Alloc Error:  ', EMS_ErrDesc[EMSResult]);
  48.           halt(1);
  49.      end;
  50.  
  51.  
  52.      { Map this page so we can use it
  53.  
  54.                                This is the physical page in the frame to
  55.                                | assign our logical page to.
  56.      This is the logical page  |
  57.  This is the EMS handle     |  |
  58.                       v     v  v }
  59.      if (not EMSMap(Handle, 0, 0)) then
  60.      begin
  61.           { There was an EMS error, so display the description }
  62.           writeln('EMS Map Error:  ', EMS_ErrDesc[EMSResult]);
  63.           EMSFree(handle);
  64.           halt(1);
  65.      end;
  66.  
  67.  
  68.      { Here is the string we will put into the EMS page }
  69.      s := 'This is a test string for EMS!';
  70.  
  71.      { Store the string length in bytes so we know how much to store
  72.        and restore }
  73.      stlen := length(s);
  74.  
  75.  
  76.      { Print the string before it goes into EMS }
  77.      writeln('String before being pushed into EMS : "', s, '"');
  78.  
  79.  
  80.      { Move the string into EMS (page 0)
  81.  
  82.                           This is the pointer to the EMS physical page 0
  83.  MkPtr creates a pointer  |
  84.  to our string |          |         How many bytes to 'move' into EMS
  85.                |          |         |
  86.                v          v         v        }
  87.      move(mkptr(s)^, EMSPage(0)^, stlen);
  88.  
  89.  
  90.      { Erase the string, so no trace is found! }
  91.      s:='';
  92.      writeln('String after it is nulled           : "', s, '"');
  93.  
  94.  
  95.      { Copy the string back from EMS (page 0) - Works the same way as
  96.        the 'move' above does, except we reversed the parameters. }
  97.      move(EMSPage(0)^, mkptr(s)^, stlen);
  98.  
  99.  
  100.      writeln('String after being restored from EMS: "', s, '"');
  101.  
  102.      readkey;
  103.  
  104.  
  105.      { Free the EMS page we allocated earlier }
  106.      EMSFree(handle);
  107.  
  108.      { Check for EMS error }
  109.      if (EMSResult>=$80) then
  110.      begin
  111.           { There was an EMS error, so display the description }
  112.           writeln('EMS Free Error:  ', EMS_ErrDesc[EMSResult]);
  113.           halt(1);
  114.      end;
  115.  
  116.      halt(0);
  117. end.
  118.